﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Manazra.Helpers;

namespace Manazra
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //  ****************    authors pages routes   ****************    //

            routes.MapRouteWithName(
                "AuthorsPopularAndPaged",                                              // Route name
                "Authors/{id}/Popular/Page/{page}",                           // URL with parameters
                new { controller = "Authors", action = "Popular", id = "" },  // Parameter defaults
                null
             );

            routes.MapRouteWithName(
                "AuthorsPaged",                                              // Route name
                "Authors/{id}/Page/{page}",                           // URL with parameters
                new { controller = "Authors", action = "Index", id = "" },  // Parameter defaults
                null
             );
            
            routes.MapRouteWithName(
                "Authors",                                              // Route name
                "Authors/{id}",                           // URL with parameters
                new { controller = "Authors", action = "Index", id="" },  // Parameter defaults
                null
             );

            //  ****************    articles pages routes   ****************    //

            routes.MapRouteWithName(
                "Paged",                                              // Route name
                "Articles/Page/{page}",                           // URL with parameters
                new { controller = "Articles", action = "Index" },  // Parameter defaults
                null
             );

            routes.MapRouteWithName(
                "PagedAndPopular",                                              // Route name
                "Articles/Popular/Page/{page}",                           // URL with parameters
                new { controller = "Articles", action = "Popular" },  // Parameter defaults
                null
            );

            //  ****************    categories pages routes   ****************    //

            routes.MapRouteWithName(
                "PagedCategories",                                              // Route name
                "Articles/Category/{id}/Page/{page}",                           // URL with parameters
                new { controller = "Articles", action = "Category", id = "" },  // Parameter defaults
                null
            );

            routes.MapRouteWithName(
                "PagedAndPopularCategories",                                              // Route name
                "Articles/Popular/Category/{id}/Page/{page}",                           // URL with parameters
                new { controller = "Articles", action = "CategoryAndPopular", id = "" },  // Parameter defaults
                null
            );

            //  ****************    blogs pages routes   ****************    //

            routes.MapRouteWithName(
               "PagedBlogs",                                              // Route name
               "Blogs/Page/{page}",                           // URL with parameters
               new { controller = "Blogs", action = "Index" },  // Parameter defaults
               null
            );

            //  ****************        default route       ****************    //

            routes.MapRouteWithName(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Articles", action = "Index", id = "" },  // Parameter defaults
                null
            );

        }

        protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }
    }
}